<?php
include_once "BaseDAO.php";
include_once $_SERVER['DOCUMENT_ROOT'].'/ad/sys/com/model/util/plog/classes/plog.php';


class SettleDetailDAO extends BaseDAO {
	
	public function __construct () {
		parent::__construct();
		$this->log = Plog::factory(__FILE__);			
	}
	
	public function getSettleDetil($account) {
		$sql = "select * from settledetail where account='$account' order by createtime desc";
		$result = @mysql_query($sql);
		return $this->toArray($result);
		
	}
	
	public function  batchUpdate($account,$uptData) {
		$sumCount = 0;
		foreach($uptData as $kye=>$value) {
			$id = $uptData->$kye->id;
			$count = $uptData->$kye->count;
			$memo = $uptData->$kye->memo;
			$settle = $uptData->$kye->settle;
			$chkSettle  = $uptData->$kye->chkSettle;
		    $sum = $uptData->$kye->sum;
			$sql = "update settledetail set count=$count , settle=$settle ,memo='$memo', chkSettle=$chkSettle where id=$id"; 
			
			@mysql_query($sql);
			//if ($chkSettle == 1) {
				$sumCount +=$sum;
			//}
		}
		
		$userSql = "select count from user where account='$account'";
		$nowCount = mysql_fetch_row( mysql_query($userSql)); 
		
		$sumCount+=$nowCount[0];
		//$this->log->debug($nowCount[0]." ".$sumCount);
		$userSql = "update user set count=$sumCount where account='$account'";
		mysql_query($userSql);
	}
	
	public function insertByAccount($account) {
		$sql = "insert into settledetail (account) values('$account')";
		$result = @mysql_query($sql);
		$id = @mysql_insert_id();
		$sqlById = "select * from settledetail where id = $id";
		return $this->toArray(@mysql_query($sqlById));
	}
}

?>